package com.www.applyword.ui.home;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.allen.library.SuperButton;
import com.allen.library.SuperTextView;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.tencent.imsdk.TIMConversationType;
import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.JobWorkAdapter;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.LoginBean;
import com.www.applyword.bean.OrderBean;
import com.www.applyword.bean.OrderDetail;
import com.www.applyword.bean.OrderItemBean;
import com.www.applyword.bean.WXPayBean;
import com.www.applyword.event.EventConstants;
import com.www.applyword.event.MessageEvent;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.ui.chat.ChatActivity;
import com.www.applyword.ui.my.ResetPayActivity;
import com.www.applyword.utils.CommonUtil;
import com.www.applyword.utils.ImageUtil;
import com.www.applyword.utils.SPUtil;
import com.www.applyword.utils.Utils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;

import static com.www.applyword.utils.Utils.getDeviceDensity;

/**
 * author : huang
 * date   : 2019/10/21 0021 16:48
 * version: 1.0
 *
 * @author Administrator
 */
public class HotJobDetailsActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.ll_contract)
    LinearLayout llContract;
    @BindView(R.id.st_apply)
    SuperTextView stApply;
    @BindView(R.id.rl_job_workfare)
    RecyclerView rl_job_workfare;
    @BindView(R.id.ll_apply)
    LinearLayout llApply;
    @BindView(R.id.ll_bond)
    LinearLayout ll_bond;
    @BindView(R.id.tv_Order_Title)
    TextView tvOrderTitle;
    @BindView(R.id.tv_Order_Salary)
    TextView tvOrderSalary;
    @BindView(R.id.tv_jiesai_type)
    TextView tvJiesaiType;
    @BindView(R.id.tv_area)
    TextView tvArea;
    @BindView(R.id.tv_Order_CreateTime)
    TextView tvOrderCreateTime;
    @BindView(R.id.tv_Order_Sex)
    TextView tvOrderSex;
    @BindView(R.id.tv_Order_Age)
    TextView tvOrderAge;
    @BindView(R.id.tv_Order_WorkYears)
    TextView tvOrderWorkYears;
    @BindView(R.id.tv_Order_Education)
    TextView tvOrderEducation;
    @BindView(R.id.tv_Order_PositionDescribe)
    TextView tvOrderPositionDescribe;
    @BindView(R.id.tv_job_category)
    TextView tvJobCategory;
    @BindView(R.id.tv_job_time)
    TextView tvJobTime;
    @BindView(R.id.tv_job_address)
    TextView tvJobAddress;
    @BindView(R.id.tv_com)
    TextView tv_com;
    @BindView(R.id.tv_Order_Num)
    TextView tv_Order_Num;
    @BindView(R.id.st_company)
    SuperTextView stCompany;
    @BindView(R.id.ll_counsel)
    LinearLayout llCounsel;
    @BindView(R.id.st_contract)
    SuperTextView stContract;
    boolean flag = false;
    @BindView(R.id.sb_apply2)
    SuperButton sbApply;
    @BindView(R.id.sb_edit)
    SuperButton sbEdit;
    @BindView(R.id.view)
    View view;
    @BindView(R.id.location_mapview)
    MapView locationMapview;
    @BindView(R.id.cb1)
    CheckBox cb1;
    @BindView(R.id.cb2)
    CheckBox cb2;
    @BindView(R.id.cb3)
    CheckBox cb3;
    @BindView(R.id.tv_job_data)
    TextView tvJobData;
    private JobWorkAdapter mJobWorkAdapter;
    private List<String> strings;
    private List<String> strings2 = new ArrayList<>();
    private String order_id;
    private int type2;
    private String orderItem_userID;
    private String order_businessID;
    private String orderItem_userID1;
    private String userInfo_nickName;
    private String userInfo_mobile;
    private PopupWindow mValidatePayPasswordPopWindow;
    private EditText et_password;
    private Double money;
    private int order_state;
    private String order_id1;
    private OrderDetail orderDetail2;
    private MapView mapView;
    private AMap aMap;//地图控制器对象
    private double order_workLat;
    private double order_workLng;
    private String order_workDetailedAddress;
    private String url;
    private Object order_oldOrderID;
    private String orderItemsID;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapView = (MapView) findViewById(R.id.location_mapview);
        mapView.onCreate(savedInstanceState);
        //初始化地图控制器对象
        if (mapView != null) {
            aMap = mapView.getMap();
            // 自定义系统定位小蓝点
            MyLocationStyle myLocationStyle = new MyLocationStyle();
            myLocationStyle.strokeColor(0x7F0070D9);// 设置圆形的边框颜色
            myLocationStyle.radiusFillColor(0x130070D9);// 设置圆形的填充颜色
            myLocationStyle.strokeWidth(1.0f);// 设置圆形的边框粗细
            // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE);//定位一次，且将视角移动到地图中心点
            //  aMap.setMyLocationStyle(myLocationStyle);
            //  //设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
            //  aMap.setMyLocationEnabled(true);
            // 设置地图的缩放级别取值范围[3-20]值越大，显示的越详细
            aMap.getUiSettings().setZoomControlsEnabled(false);
            //  aMap.moveCamera(CameraUpdateFactory.zoomTo(14f));
        }
    }

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.hot_job_details_activity);
        setTitle("职位详情");
        bt_checkBox.setVisibility(View.VISIBLE);
    //    ib_share.setVisibility(View.VISIBLE);
        bt_checkBox.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
        bt_checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                addCollection();
            } else {
                deleteCollection();
            }
        });

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

        //分享
        ib_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare();
            }
        });
        //地图
        view.setOnClickListener(v -> startActivity(new Intent(HotJobDetailsActivity.this, LocationInfoActivity.class)
                .putExtra("order_workLat", order_workLat)
                .putExtra("address", order_workDetailedAddress)
                .putExtra("order_workLng", order_workLng)));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent messageEvent) {
        if (messageEvent.getMessageKey() != null) {
            if (messageEvent.getMessageKey().equals(EventConstants.PAY)) {
                finish();
            }
        }
    }


    @Override
    protected void loadData() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rl_job_workfare.setLayoutManager(layoutManager);
        mJobWorkAdapter = new JobWorkAdapter(this);
        rl_job_workfare.setAdapter(mJobWorkAdapter);

        getOrderInfo();
    }

    private void getOrderInfo() {
        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", getIntent().getStringExtra("OrderID"));
        params.put("UserID", SPUtil.getString(Constants.USERID));
        HttpClient.get(HotJobDetailsActivity.this, Constants.GETRECRUITINFORMATION, params, new CallBack<OrderDetail>() {
            @Override
            public void onSuccess(OrderDetail orderDetail) {
                orderDetail2 = orderDetail;
                order_workLat = orderDetail.getOrder().getOrder_WorkLat();
                order_workLng = orderDetail.getOrder().getOrder_WorkLng();
                order_workDetailedAddress = orderDetail.getOrder().getOrder_WorkDetailedAddress();
                aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(order_workLat, order_workLng), 14));
                //绘制marker
                aMap.addMarker(new MarkerOptions()
                        .position(new LatLng(order_workLat, order_workLng))
                        .draggable(true));
                order_id = orderDetail.getOrder().getOrder_ID();
                getCollection();
                if (!TextUtils.isEmpty(orderDetail.getOrder().getOrder_Welfare())) {
                    if (orderDetail.getOrder().getOrder_Welfare().contains(",")) {
                        strings = Arrays.asList(orderDetail.getOrder().getOrder_Welfare().split(","));
                        mJobWorkAdapter.replaceAll(strings, true);
                    } else {
                        strings2.clear();
                        strings2.add(orderDetail.getOrder().getOrder_Welfare());
                        mJobWorkAdapter.replaceAll(strings2, true);
                    }
                }

                if (orderDetail.getOrder().getOrder_Type() == 0) {   ////0只可承包；1承包和个人；2只可个人；Order_Type
                    cb1.setChecked(true);
                    cb1.setEnabled(false);
                } else if (orderDetail.getOrder().getOrder_Type() == 1) {
                    cb2.setChecked(true);
                    cb2.setEnabled(false);
                } else {
                    cb3.setChecked(true);
                    cb3.setEnabled(false);
                }
                cb1.setEnabled(false);
                cb2.setEnabled(false);
                cb3.setEnabled(false);

                tvOrderTitle.setText(orderDetail.getOrder().getOrder_PositionName());
                tv_Order_Num.setText("招聘人数:" + orderDetail.getOrder().getOrder_Number() + "人");
                if (orderDetail.getOrder().getOrder_SalaryType() == 0) {
                    tvOrderSalary.setText(orderDetail.getOrder().getOrder_Salary() + "/时");
                    tvArea.setText("时结 | " + orderDetail.getOrder().getOrder_WorkAddress());
                } else if (orderDetail.getOrder().getOrder_SalaryType() == 1) {
                    tvOrderSalary.setText(orderDetail.getOrder().getOrder_Salary() + "/日");
                    tvArea.setText("日结 | " + orderDetail.getOrder().getOrder_WorkAddress());
                } else {
                    tvOrderSalary.setText(orderDetail.getOrder().getOrder_Salary() + "/月");
                    tvArea.setText("月结 | " + orderDetail.getOrder().getOrder_WorkAddress());
                }
                tvOrderCreateTime.setText(orderDetail.getOrder().getOrder_CreateTime() + "发布");
                tvOrderSex.setText(orderDetail.getOrder().getOrder_Sex());
                tvOrderAge.setText(orderDetail.getOrder().getOrder_Age());
                tvOrderWorkYears.setText(orderDetail.getOrder().getOrder_WorkYears());
                tvOrderEducation.setText(orderDetail.getOrder().getOrder_Education());
                tvOrderPositionDescribe.setText(orderDetail.getOrder().getOrder_PositionDescribe());
                tvJobTime.setText("上班时间: " + orderDetail.getOrder().getOrder_HourStartTime() + "－" + orderDetail.getOrder().getOrder_HourEndTime());
                tvJobAddress.setText("上班地址: " + orderDetail.getOrder().getOrder_WorkDetailedAddress());
                tvJobData.setText("工作日期: " + orderDetail.getOrder().getOrder_StartTime().split(" ")[0] + "－" + orderDetail.getOrder().getOrder_EndTime().split(" ")[0]);
                if (orderDetail.getOrder().getOrder_PositionType() == 0) {
                    tvJobCategory.setText("工作性质: " + "兼职");
                } else {
                    tvJobCategory.setText("工作性质: " + "全职");
                }

                userInfo_nickName = orderDetail.getUser().getUserInfo_NickName();
                userInfo_mobile = orderDetail.getUser().getUserInfo_Mobile();
                //公司信息
                if (null != orderDetail.getCertificationBean() && !TextUtils.isEmpty(orderDetail.getCertificationBean().getEnterpriseCertification_Name())) {
                    type2 = 0;
                    ImageUtil.setImage(stCompany.getLeftIconIV(), orderDetail.getCertificationBean().getEnterpriseCertification_Logo());
                    stCompany.getLeftTopTextView().setText(orderDetail.getCertificationBean().getEnterpriseCertification_Name());
                    stCompany.getLeftBottomTextView().setText("联系人: " + orderDetail.getCertificationBean().getEnterpriseCertification_UserName());
                } else {
                    type2 = 1;
                    ImageUtil.setImage(stCompany.getLeftIconIV(), orderDetail.getUser().getUserInfo_HeadImg());
                    stCompany.getLeftTopTextView().setText(orderDetail.getUser().getUserInfo_NickName());
                    stCompany.getLeftBottomTextView().setText("联系人: " + orderDetail.getUser().getUserInfo_RealName());
                    ll_bond.setVisibility(View.GONE);
                    tv_com.setText("个人信息");
                }

                //der_State 状态：0报名；1确认人员；2签到；3结算；4评价；10撤回；11待支付;  //0只可承包；1承包和个人；2只可个人；Order_Type
              /*  if (orderDetail.getOrder().getOrder_Type() == 0) {
                    llApply.setVisibility(View.GONE);//报名
                    stContract.getCenterBottomTextView().setText("已有" + orderDetail.getCollectionNum() + "人申请");
                } else if (orderDetail.getOrder().getOrder_Type() == 2) {  //承包
                    llContract.setVisibility(View.GONE);
                    stApply.getCenterBottomTextView().setText("已有" + orderDetail.getPersonalNum() + "人报名");
                } else {
                    stContract.getCenterBottomTextView().setText("已有" + orderDetail.getCollectionNum() + "人申请");
                    stApply.getCenterBottomTextView().setText("已有" + orderDetail.getPersonalNum() + "人报名");
                }*/


                order_businessID = orderDetail.getOrder().getOrder_BusinessID();
                String userId = SPUtil.getString(Constants.USERID);
                SPUtil.put(userInfo_mobile + Constants.USERID, order_businessID);
                if (orderDetail.getOrder().getOrder_BusinessID().equals(userId)) { //我自己发布的
                    bt_checkBox.setVisibility(View.INVISIBLE);
                    order_id1 = orderDetail.getOrder().getOrder_ID();
                    order_oldOrderID = orderDetail.getOrder().getOrder_OldOrderID();
                    if (orderDetail.getOrder().getOrder_State() == 0) {  //报名
                        //咨询
                        llCounsel.setVisibility(View.GONE);
                        stContract.getCenterTopTextView().setText("录用");
                        stContract.getCenterBottomTextView().setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("撤回");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                        //  sbEdit.setVisibility(View.VISIBLE);
                    } else if (orderDetail.getOrder().getOrder_State() == 1) { //1确认人员  录用
                        llCounsel.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("录用");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.getOrder().getOrder_State() == 2) { //2 签到
                        llCounsel.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("已到岗");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.getOrder().getOrder_State() == 3) {
                        llCounsel.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("结算");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.getOrder().getOrder_State() == 4) {
                        llCounsel.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("评价");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.getOrder().getOrder_State() == 12) {   //转发待支付
                        llCounsel.setVisibility(View.GONE);
                        llApply.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        sbApply.setVisibility(View.VISIBLE);
                        money = orderDetail.getOrder().getOrder_Bond();
                        order_state = 12;
                    } else if (orderDetail.getOrder().getOrder_State() == 11 || orderDetail.getOrder().getOrder_State() == 10) {
                        llCounsel.setVisibility(View.GONE);
                        llApply.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        sbApply.setVisibility(View.VISIBLE);
                        sbEdit.setVisibility(View.VISIBLE);
                        money = orderDetail.getOrder().getOrder_Bond();
                        order_state = 10;
                    } else {
                        llCounsel.setVisibility(View.GONE);
                        llApply.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                    }
                } else if (null != orderDetail.OrderItem && userId.equals(orderDetail.OrderItem.OrderItem_UserID)) {  //别人的发布，我报名
                    order_id1 = orderDetail.getOrder().getOrder_ID();
                    orderItemsID = orderDetail.OrderItem.OrderItemsID;
                    if (orderDetail.OrderItem.OrderItem_ServiceCharge > 0 && orderDetail.OrderItem.OrderItem_State == 11) {
                        sbApply.setVisibility(View.VISIBLE);
                        money = orderDetail.OrderItem.OrderItem_ServiceCharge;
                        order_state = 100;
                        llCounsel.setVisibility(View.GONE);
                        llApply.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                    }
                    if (orderDetail.OrderItem.OrderItem_State == 1) {  //1待签到
                        if (orderDetail.OrderItem.OrderItem_Type.equals("1")) {
                            // stApply.setVisibility(View.GONE);
                            //  stContract.getCenterTopTextView().setText("转发");
                            //   stApply.getCenterBottomTextView().setVisibility(View.GONE);

                            llContract.setVisibility(View.GONE);
                            llCounsel.setVisibility(View.GONE);
                            stApply.getCenterTopTextView().setText("转发");
                            stApply.getCenterBottomTextView().setVisibility(View.GONE);
                        } else {
                            llCounsel.setVisibility(View.GONE);
                            llApply.setVisibility(View.GONE);
                            llContract.setVisibility(View.GONE);
                        }
                    } else if (orderDetail.OrderItem.OrderItem_State == 4) { //4异常结算/待申诉
                        orderItem_userID = orderDetail.OrderItem.OrderItem_UserID;
                        llContract.setVisibility(View.GONE);
                        llCounsel.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("申诉");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.OrderItem.OrderItem_State == 7) {  //评价
                        orderItem_userID1 = orderDetail.OrderItem.OrderItem_UserID;
                        stContract.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("评价");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.OrderItem.OrderItem_State == 10) {  //确认报名
                        llContract.setVisibility(View.GONE);
                        llCounsel.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("确认报名");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    } else if (orderDetail.OrderItem.OrderItem_State == 0 || orderDetail.OrderItem.OrderItem_State == 2) {  //待审核 和 待结算
                        llApply.setVisibility(View.GONE);
                        llContract.setVisibility(View.GONE);
                        llCounsel.setVisibility(View.GONE);
                    } else if (orderDetail.OrderItem.OrderItem_State == 13) {
                        llContract.setVisibility(View.GONE);
                        llCounsel.setVisibility(View.GONE);
                        stApply.getCenterTopTextView().setText("已转发");
                        stApply.getCenterBottomTextView().setVisibility(View.GONE);
                    }
                } else { //别人的发布，我没有报名
                    if (orderDetail.getOrder().getOrder_Type() == 0) {
                        llApply.setVisibility(View.GONE);//报名
                        stContract.getCenterBottomTextView().setText("已有" + orderDetail.getCollectionNum() + "人申请");
                    } else if (orderDetail.getOrder().getOrder_Type() == 2) {  //承包
                        llContract.setVisibility(View.GONE);
                        stApply.getCenterBottomTextView().setText("已有" + orderDetail.getPersonalNum() + "人报名");
                    } else {
                        stContract.getCenterBottomTextView().setText("已有" + orderDetail.getCollectionNum() + "人申请");
                        stApply.getCenterBottomTextView().setText("已有" + orderDetail.getPersonalNum() + "人报名");
                    }

                   /* if (orderDetail.getOrder().getOrder_Type() == 0) {  //只可承包
                        stApply.setVisibility(View.GONE);
                    } else if (orderDetail.getOrder().getOrder_Type() == 1) { //承包和个人

                    } else { //只可个人  2只可个人；
                        //承包隐藏
                        stContract.setVisibility(View.GONE);
                    }*/
                }
            }
        });
    }

    //分享
    private void showShare() {
        setBackgroundAlpha((float) 0.4);
        // mapView.setVisibility(View.INVISIBLE);
        View view = LayoutInflater.from(HotJobDetailsActivity.this).inflate(R.layout.dialog_share_item, null);
        PopupWindow mPopWindow = new PopupWindow(view,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(view);
        // 设置PopupWindow的背景
        mPopWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mPopWindow.setOutsideTouchable(true);
        mPopWindow.setTouchable(true);

        mPopWindow.getContentView().setFocusable(true); // 这个很重要
        mPopWindow.getContentView().setFocusableInTouchMode(true);
        mPopWindow.getContentView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    mPopWindow.dismiss();
                    //  mapView.setVisibility(View.VISIBLE);
                    return true;
                }
                return false;
            }
        });

        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mapView.setVisibility(View.VISIBLE);
            }
        });


        view.findViewById(R.id.ll_weixin).setOnClickListener(v -> {
            String url = "http://yikuaijianzhi.whmnx.com/Share/jobInfo.html?orderId=" + order_id;
            Platform platform = ShareSDK.getPlatform(Wechat.NAME);
            Platform.ShareParams shareParams = new Platform.ShareParams();
            shareParams.setTitle("一块兼职");
            shareParams.setText("一块兼职");
            //  shareParams.setImageUrl(String.valueOf(R.mipmap.job_logo));
            shareParams.setUrl(url);
            //分享网页
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            platform.share(shareParams);

        });

        view.findViewById(R.id.ll_pyquan).setOnClickListener(v -> {
            String url = "http://yikuaijianzhi.whmnx.com/Share/jobInfo.html?orderId=" + order_id;
            Platform platform = ShareSDK.getPlatform(Wechat.NAME);
            Platform.ShareParams shareParams = new Platform.ShareParams();
            shareParams.setTitle("一块兼职");
            shareParams.setText("一块兼职");
            // shareParams.setImageUrl(String.valueOf(R.mipmap.job_logo));
            shareParams.setUrl(url);
            //分享网页
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            platform.share(shareParams);

        });

        View rootView = LayoutInflater.from(HotJobDetailsActivity.this).inflate(R.layout.login_activity, null);
        mPopWindow.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1);
                mapView.setVisibility(View.VISIBLE);
            }
        });
    }


    private void getSignUpOrder(int type2) {
        Map<String, Object> params2 = new HashMap<>();
        params2.put("UserID", SPUtil.getString(Constants.USERID));
        params2.put("OrderID", order_id);
        //  params2.put("Type", type2 + "");
        if (type2 == 0) {
            url = Constants.PAYMENTSERVICECHARGE;
        } else {
            params2.put("Type", type2 + "");
            url = Constants.SIGNUPORDER;
        }
        HttpClient.get(HotJobDetailsActivity.this, url, params2, new CallBack<WXPayBean>() {
            @Override
            public void onSuccess(WXPayBean wxPayBean) {
                //    getOrderInfo();
                //我要报名
                if (type2 == 0) {
                    Utils.showToastSafe("报名成功");
                    stApply.getCenterTopTextView().setText("已报名");
                    getOrderInfo();
                } else {
                    Utils.showToastSafe("申请包揽成功");
                    stContract.getCenterTopTextView().setText("已申请包揽");
                    getOrderInfo();
                }
            }
        });
    }

    private void getCollection() {
        Map<String, Object> params2 = new HashMap<>();
        params2.put("UserID", SPUtil.getString(Constants.USERID));
        params2.put("Page", 1 + "");
        params2.put("Rows", 20 + "");
        HttpClient.get(HotJobDetailsActivity.this, Constants.GETCOLLECTIONLIST, params2, new CallBack<List<OrderBean>>() {
            @Override
            public void onSuccess(List<OrderBean> orderBeans) {
                for (OrderBean orderBean : orderBeans) {
                    if (orderBean.getOrder_ID().equals(order_id)) {
                        bt_checkBox.setChecked(true);
                    }
                }
            }
        });
    }


    @OnClick({R.id.ll_counsel, R.id.st_contract, R.id.st_apply, R.id.st_company, R.id.sb_apply2, R.id.sb_edit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //咨询
            case R.id.ll_counsel:
                ChatInfo chatInfo = new ChatInfo();
                chatInfo.setType(TIMConversationType.C2C);
                chatInfo.setId(userInfo_mobile);
                chatInfo.setChatName(userInfo_nickName);
                Intent intent = new Intent(HotJobDetailsActivity.this, ChatActivity.class);
                intent.putExtra(Constants.CHAT_INFO, chatInfo);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            //承包
            case R.id.st_contract:
                ////GET /SignUpOrder
                if (stContract.getCenterTopTextView().getText().equals("申请包揽")) {
                    getSignUpOrder(1);
                } else if (stContract.getCenterTopTextView().getText().equals("录用")) {
                    // Utils.startActivity(EmployedActivity.class);
                    startActivity(new Intent(this, EmployedActivity.class).putExtra("OrderID", order_id));
                } else {

                }

                break;
            //报名
            case R.id.st_apply:
                if (stApply.getCenterTopTextView().getText().equals("我要报名") || stApply.getCenterTopTextView().getText().equals("确认报名")) {
                    getSignUpOrder(0);
                } else if (stApply.getCenterTopTextView().getText().equals("撤回")) {
                    withdrawOrder();
                } else if (stApply.getCenterTopTextView().getText().equals("申诉")) {
                    appealAbnormalSettlement();
                } else if (stApply.getCenterTopTextView().getText().equals("评价")) {
                    startActivity(new Intent(this, CommentActivity.class)
                            .putExtra("BusinessID", order_businessID)
                            .putExtra("OrderItemsID", orderItem_userID1));
                } else if (stApply.getCenterTopTextView().getText().equals("结算")) {
                    startActivity(new Intent(this, SettlementActivity.class).putExtra("OrderID", order_id));
                } else if (stApply.getCenterTopTextView().getText().equals("转发")) {
                    startActivity(new Intent(this, PostJobActivity.class).putExtra("OrderDetail", orderDetail2).putExtra("type", 1));
                }

                break;
            case R.id.st_company:
                startActivity(new Intent(this, CompanyInfoActivity.class).putExtra("OrderID", order_id).putExtra("type", type2));
                break;
            //支付
            case R.id.sb_apply2:
                //设置支付密码
                // PayDialogFragment editNameDialogFragment = PayDialogFragment.newInstance("￥ " + money);
                //  editNameDialogFragment.show(getSupportFragmentManager(), "pay");
                showPossWord();
                break;
            //编辑
            case R.id.sb_edit:
                startActivity(new Intent(this, PostJobActivity.class).putExtra("OrderDetail", orderDetail2));
                break;
            default:
        }
    }

    private String alreadyInputPassword;
    private boolean isFirstInputPassword = true;
    private boolean isCanClear = true;

    private void showPossWord() {
        setBackgroundAlpha((float) 0.4);
        View contentView = LayoutInflater.from(this).inflate(R.layout.popwindow_validate_pay_password, null);
        et_password = contentView.findViewById(R.id.et_password);
        final TextView tv_pwd_one = contentView.findViewById(R.id.tv_pwd_one);
        final TextView tv_pwd_two = contentView.findViewById(R.id.tv_pwd_two);
        final TextView tv_pwd_three = contentView.findViewById(R.id.tv_pwd_three);
        final TextView tv_pwd_four = contentView.findViewById(R.id.tv_pwd_four);
        final TextView tv_pwd_five = contentView.findViewById(R.id.tv_pwd_five);
        final TextView tv_pwd_six = contentView.findViewById(R.id.tv_pwd_six);
        final ImageView iv_close = contentView.findViewById(R.id.iv_close);
        final TextView tv_forget_password = contentView.findViewById(R.id.tv_forget_password);
        final TextView tv_money = contentView.findViewById(R.id.tv_money);

        tv_money.setText("￥ " + new DecimalFormat("#.00").format(money));
        tv_pwd_one.setOnClickListener(this);
        tv_pwd_two.setOnClickListener(this);
        tv_pwd_three.setOnClickListener(this);
        tv_pwd_four.setOnClickListener(this);
        tv_pwd_five.setOnClickListener(this);
        tv_pwd_six.setOnClickListener(this);
        iv_close.setOnClickListener(this);
        tv_forget_password.setOnClickListener(this);

        et_password.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // et_password.setTextColor(getResources().getColor(R.color.white));
                switch (s.length()) {
                    case 0:
                        if (isCanClear) {
                            tv_pwd_one.setText("");
                        }
                        break;
                    case 1:
                        tv_pwd_one.setText(s.toString().substring(0, 1));
                        tv_pwd_two.setText("");
                        break;
                    case 2:
                        tv_pwd_two.setText(s.toString().substring(1, 2));
                        tv_pwd_three.setText("");
                        break;
                    case 3:
                        tv_pwd_three.setText(s.toString().substring(2, 3));
                        tv_pwd_four.setText("");
                        break;
                    case 4:
                        tv_pwd_four.setText(s.toString().substring(3, 4));
                        tv_pwd_five.setText("");
                        break;
                    case 5:
                        tv_pwd_five.setText(s.toString().substring(4, 5));
                        tv_pwd_six.setText("");
                        break;
                    case 6:
                        if (!isFirstInputPassword) {
                            if (s.toString().equals(alreadyInputPassword)) {
                                //密码通过
                                setPayPwd(alreadyInputPassword);
                                et_password.setText("");
                            } else {
                                //
                            }
                        }
                        tv_pwd_six.setText(s.toString().substring(5, 6));
                        if (isFirstInputPassword) {
                            alreadyInputPassword = s.toString();
                            if (s.toString().equals(alreadyInputPassword))
                                setPayPwd(alreadyInputPassword);
                            // isFirstInputPassword = false;
                        }

                        //  Utils.showToastSafe("支付密码输入错误");
                        tv_pwd_one.setText("");
                        tv_pwd_two.setText("");
                        tv_pwd_three.setText("");
                        tv_pwd_four.setText("");
                        tv_pwd_five.setText("");
                        tv_pwd_six.setText("");
                        isCanClear = false;
                        et_password.setText("");
                        isCanClear = true;
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });


        mValidatePayPasswordPopWindow = new PopupWindow(contentView,
                (int) (getDeviceDensity().widthPixels / 1.1), LinearLayout.LayoutParams.WRAP_CONTENT, true);
        mValidatePayPasswordPopWindow.setContentView(contentView);
        mValidatePayPasswordPopWindow.setFocusable(true);

        //设置获得焦点，否则无法点击
        //   mValidatePayPasswordPopWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        //   mValidatePayPasswordPopWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        View rootView = LayoutInflater.from(this).inflate(R.layout.hot_job_activity, null);
        mValidatePayPasswordPopWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0);
        // openKeybord();
        mValidatePayPasswordPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1);
            }
        });
    }

    private void openKeybord() {
        InputMethodManager imm = (InputMethodManager) HotJobDetailsActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }


    //验证支付密码
    private void setPayPwd(String alreadyInputPassword) {
        Map<String, Object> params = new HashMap<>();
        params.put("UserID", SPUtil.getString(Constants.USERID));
        params.put("Pwd", alreadyInputPassword);
        HttpClient.get(HotJobDetailsActivity.this, Constants.VERIFICATIONPWDBY, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                mValidatePayPasswordPopWindow.dismiss();
                if (order_state == 12) {  //转发
                    Map<String, Object> params = new HashMap<>();
                    params.put("OrderID", order_id1);
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    params.put("OldOrderID", order_oldOrderID);
                    HttpClient.get(HotJobDetailsActivity.this, Constants.TURNOUTORDERMONEY, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            Utils.showToastSafe("支付成功");
                            sbApply.setVisibility(View.INVISIBLE);
                            MessageEvent messageEvent = new MessageEvent();
                            messageEvent.setMessageKey(EventConstants.PAY);
                            EventBus.getDefault().post(messageEvent);
                            finish();
                            //  getOrderInfo();
                        }
                    });
                } else if (order_state == 100) {   //别人发布，我报名，支付手续费
                    Map<String, Object> params = new HashMap<>();
                    params.put("OrderID", order_id1);
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    HttpClient.get(HotJobDetailsActivity.this, Constants.PAYMENTSERVICECHARGEMONEY, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            Utils.showToastSafe("支付成功");
                            sbApply.setVisibility(View.INVISIBLE);
                            MessageEvent messageEvent = new MessageEvent();
                            messageEvent.setMessageKey(EventConstants.PAY);
                            EventBus.getDefault().post(messageEvent);
                            finish();
                            //    getOrderInfo();
                        }
                    });
                } else {
                    Map<String, Object> params = new HashMap<>();
                    params.put("OrderID", order_id1);
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    params.put("PayPwd", alreadyInputPassword);
                    HttpClient.get(HotJobDetailsActivity.this, Constants.CALCULATIONMONEY, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            Utils.showToastSafe("支付成功");
                            sbApply.setVisibility(View.INVISIBLE);
                            MessageEvent messageEvent = new MessageEvent();
                            messageEvent.setMessageKey(EventConstants.PAY);
                            EventBus.getDefault().post(messageEvent);
                            finish();
                            //    getOrderInfo();
                        }
                    });
                }
            }
        });
    }

    private void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = bgAlpha;
        getWindow().setAttributes(lp);
        mapView.setVisibility(View.INVISIBLE);
    }

    //申诉
    private void appealAbnormalSettlement() {
        Map<String, Object> params = new HashMap<>();
        params.put("OrderItemsID", orderItemsID);
        HttpClient.get(HotJobDetailsActivity.this, Constants.APPEALABNORMALSETTLEMENT, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                //  Utils.showToastSafe("支付密码验证成功");
                Utils.showToastSafe("申诉成功");

            }
        });
    }

    //撤回
    private void withdrawOrder() {
        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", order_id);
        params.put("Page", 1 + "");
        params.put("Rows", 10 + "");
        HttpClient.get(HotJobDetailsActivity.this, Constants.GETORDERITEMS, params, new CallBack<List<OrderItemBean>>() {
            @Override
            public void onSuccess(List<OrderItemBean> orderBeans) {
                if (orderBeans.size() > 0) {
                    Utils.showToastSafe("已确认报名该订单不可撤回");
                    return;
                }
                Map<String, Object> params = new HashMap<>();
                params.put("OrderID", order_id);

                HttpClient.get(HotJobDetailsActivity.this, Constants.WITHDRAWORDER, params, new CallBack<String>() {
                    @Override
                    public void onSuccess(String result) {
                        MessageEvent messageEvent = new MessageEvent();
                        messageEvent.setMessageKey(EventConstants.PAY);
                        EventBus.getDefault().post(messageEvent);
                        finish();
                    }
                });
            }
        });
    }


    private void addCollection() {
        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", order_id);
        params.put("UserID", SPUtil.getString(Constants.USERID));

        HttpClient.get(HotJobDetailsActivity.this, Constants.ADDCOLLECTION, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                //  Utils.showToastSafe("收藏成功");
            }
        });
    }

    private void deleteCollection() {
        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", order_id);
        params.put("UserID", SPUtil.getString(Constants.USERID));

        HttpClient.get(HotJobDetailsActivity.this, Constants.DELETECOLLECTION, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                Utils.showToastSafe("取消收藏成功");
            }
        });
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_pwd_one:
            case R.id.tv_pwd_two:
            case R.id.tv_pwd_three:
            case R.id.tv_pwd_four:
            case R.id.tv_pwd_five:
            case R.id.tv_pwd_six:
                CommonUtil.showKeyboard(this, et_password, true);
                break;
            case R.id.iv_close:
                mValidatePayPasswordPopWindow.dismiss();
                mapView.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_forget_password:
                Utils.startActivity(ResetPayActivity.class);
                mValidatePayPasswordPopWindow.dismiss();
                mapView.setVisibility(View.VISIBLE);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mapView.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mapView.onSaveInstanceState(outState);
    }

}
